//
//  YPZQRecordViewController.m
//  ChengHuiTong
//
//  Created by CHT-Technology on 2017/2/21.
//  Copyright © 2017年 张文权. All rights reserved.
//

#import "YPZQRecordViewController.h"
#import "YPZQApplyViewController.h"
#import "DQDScrollContentView.h"
#import "YPContentItemView.h"
@interface YPZQRecordViewController ()<DQDScrollContentViewDataSource>{
    
    NSArray *_titlesArray;
    
}

@property (nonatomic,weak)YPContentItemView *zrzContentItemView;
@property (nonatomic,strong)DQDScrollContentView *contentView;

@end

@implementation YPZQRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"债权转让";
    
    _titlesArray = @[@"可转让",@"转让中",@"已转让",@"已认购"];
    
    [self setUpUI];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [MobClick beginLogPageView:@"债权转让"];
}

- (void) viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"债权转让"];
    
}

- (void)setUpUI{
    
    _contentView = [[DQDScrollContentView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) topScrollEnabled:NO showTopScrollLine:NO];
    _contentView.dataSource = self;
    [self.view addSubview:_contentView];
}

#pragma mark --DQDScrollContentViewDataSource
- (NSArray *)homeViewWithTitleArray{
    
    return _titlesArray;
}

- (DQDScrollContentItemView *)homeViewItemWithContentViewWithIndex:(NSInteger)index{
    
    YPContentItemView *contentItemView = [[YPContentItemView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    if(index == 1)self.zrzContentItemView = contentItemView;
    contentItemView.tableViewDidSelectBlock = ^{
        
    };
    __weak typeof(contentItemView) weakContentView = contentItemView;
    WeakSelf
    contentItemView.applyBlock = ^(YPZQRecordModel *model){
        
        if (model.transferable.integerValue == 0) {
            YPZQApplyViewController * applyVC = [YPZQApplyViewController new];
            applyVC.tender_id = model.tender_id;
            applyVC.applyCompleteBlock = ^{
                [weakSelf.contentView.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
                [weakContentView.header beginRefreshing];
                [weakSelf.zrzContentItemView.header beginRefreshing];
            };
            
            [weakSelf.navigationController pushViewController:applyVC animated:YES];
        }else if (model.transferable.integerValue == 1){
            
             [MBProgressHUD showError:@"已有一笔债权处于转让中，无法同时转让两个债权" toView:weakSelf.navigationController.view];
        }else{
             [MBProgressHUD showError:@"项目临近还款日，暂不可转让" toView:weakSelf.navigationController.view];
            
        }
        
    };
    return contentItemView;
}

@end
